package com.codingvip.tree;

/**
 * @Author Tony.Han
 * @Created at 2020/4/5 6:33 下午
 * Desc:
 */
public class TreeToDubboList {
    Node first,last;
    public Node treeToDoublyList(Node root) {

        if(null==root){
            return root;
        }
        inOrderVisiter(root);
        last.right=first;
        first.left=last;
        return first;

    }
    void inOrderVisiter(Node root){
        if(root==null){
            return;
        }
        inOrderVisiter(root.left);

        if(last==null){
            first=root;
        }else{
            last.right=root;
            root.left=last;
        }
        last=root;
        inOrderVisiter(root.right);
    }
}
